package org.usmile.algorithms.huawei.acm;

import java.util.Scanner;

// https://fcqian.blog.csdn.net/article/details/128383284
public class _查找单入口空闲区域 {
    private static String[][] metric;
    private static boolean[][] visited;
    private static int rows;
    private static int cols;
    private static final int[][] directions = new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        rows = sc.nextInt();
        cols = sc.nextInt();
        sc.nextLine();
        metric = new String[rows][cols];
        visited = new boolean[rows][cols];
        for (int row = 0; row < rows; row++) {
            metric[row] = sc.nextLine().split(" ");
        }

        int max = Integer.MIN_VALUE;
        int startRow = -1;
        int startCol = -1;
        // 第一行
        for (int col = 0; col < cols; col++) {
            if (metric[0][col].equals("O")) {
                if (!visited[0][col]) {
                    visited[0][col] = true;
                    int count = dfs(0, col);
                    if (count != -1) {
                        max = Math.max(max, count);
                        startRow = 0;
                        startCol = col;
                    }
                }
            }
        }
        for (int row = 0; row < rows; row++) {
            if (metric[row][0].equals("O")) {
                if (!visited[row][0]) {
                    visited[row][0] = true;
                    int count = dfs(row, 0);
                    if (count != -1) {
                        max = Math.max(max, count);
                        startRow = row;
                        startCol = 0;
                    }
                }
            }
        }
        for (int col = 0; col < cols; col++) {
            if (metric[rows - 1][col].equals("O")) {
                if (!visited[rows - 1][col]) {
                    visited[rows - 1][col] = true;
                    int count = dfs(rows - 1, col);
                    if (count != -1) {
                        max = Math.max(max, count);
                        startRow = rows - 1;
                        startCol = col;
                    }
                }
            }
        }
        for (int row = 0; row < rows; row++) {
            if (metric[row][cols - 1].equals("O")) {
                if (!visited[row][cols - 1]) {
                    visited[row][cols - 1] = true;
                    int count = dfs(row, cols - 1);
                    if (count != -1) {
                        max = Math.max(max, count);
                        startRow = row;
                        startCol = cols - 1;
                    }
                }
            }
        }
        if (max == Integer.MIN_VALUE) {
            System.out.println("NULL");
        } else {
            System.out.println(max + " " + startRow + " " + startCol);
        }
    }

    private static int dfs(int row, int col) {
        int count = 1;
        boolean flag = false;
        for (int[] direction : directions) {
            int nextRow = row + direction[0];
            int nextCol = col + direction[1];
            if (nextRow >= 0 && nextRow < rows && nextCol >= 0 && nextCol < cols) {
                if (!visited[nextRow][nextCol] && metric[nextRow][nextCol].equals("O")) {
                    visited[nextRow][nextCol] = true;
                    if (nextRow == 0 || nextRow == rows - 1 || nextCol == 0 || nextCol == cols - 1) {
                        flag = true;
                    }
                    int curr = dfs(nextRow, nextCol);
                    if (curr == -1) {
                        flag = true;
                    }
                    count += curr;
                }
            }
        }

        return flag ? -1 : count;
    }
}
